<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: legion
  Date: 2021/10/18
  Time: 8:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表页面</title>
    <script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
    <link rel="stylesheet" href="/resource/css/index3.css">
</head>
<body>
<h1>列表页面</h1>
<form action="list" method="post">
    <input type="hidden" name="pageNum">
    <input type="hidden" name="px" value="${vo.px}">
    商品名称:<input type="text" name="name" value="${vo.name}">
    商品品牌:<select name="tid">
    <option value="">--请选择--</option>
    <c:forEach items="${list}" var="type">
        <option value="${type.tid}" ${type.tid==vo.tid?'selected':''}>${type.tname}</option>
    </c:forEach>
</select>

    <input type="submit" value="搜索">
</form>

<input type="button" value="添加商品" onclick="add()">
<table>
    <tr>
        <td><input type="checkbox" name="cc" onclick="qx()">全选</td>
        <td>商品编号</td>
        <td>商品名称</td>
        <td>商品价格 <input type="button" value="↓" onclick="px(1)">
<%--            <input type="button" value="↑" onclick="px(0)"></td>--%>
        <td>商品上架时间</td>
        <td>商品品牌</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${info.list}" var="g">
        <tr>
            <td><input type="checkbox" name="ck" value="${g.gid}"></td>
            <td>${g.gid}</td>
            <td>${g.gname}</td>
            <td>${g.gprice}</td>
            <td>
                <fmt:formatDate value="${g.gtime}" pattern="yyyy-MM-dd"></fmt:formatDate>
            </td>
            <td>${g.tname}</td>
            <td>
                <input type="button" value="修改" onclick="update(${g.gid})">
                <input type="button" value="查看" onclick="ck(${g.gid})">
            </td>
        </tr>

    </c:forEach>
    <tr>
        <td colspan="10"><jsp:include page="page.jsp"></jsp:include></td>
    </tr>
</table>
<input type="button" value="批量删除" onclick="delAll()">

<script >

    function goPage(pageNum) {
        $('[name="pageNum"]').val(pageNum)
        $("form").submit()
    }
    function add() {
        location="toAdd";
    }
    function update(id) {
        location="toUpdate?id="+id;
    }
    function qx() {
        $('[name="ck"]').attr("checked",true);
    }
    function delAll() {
        var gids="";
        $('[name="ck"]:checked').each(function () {
            gids+=","+$(this).val();
        })
        gids=gids.substring(1)
        alert(gids)
        if (confirm("确认删除")){
            $.post("delAll",{gids:gids},function (result) {
                if (result){
                    alert("删除成功")
                    location.reload()
                }else {
                    alert("删除失败")
                }
            })
        }

    }
    
    function px(num) {

      var px= $('[name="px"]').val();
      // alert(px)
      if (px!=null){
          $('[name="px"]').val(${o}+num)
      }else {
          $('[name="px"]').val(num)
      }

        // alert($('[name="px"]').val());
        $("form").submit();
    }

    function ck(id) {
        location="ck?id="+id;

    }
</script>
</body>
</html>
